package com.ruoyi.sports.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.sports.domain.SportsMeeting;
import com.ruoyi.sports.domain.vo.EventVO;
import com.ruoyi.sports.mapper.SportsMeetingMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.sports.mapper.EventMapper;
import com.ruoyi.sports.domain.Event;
import com.ruoyi.sports.service.IEventService;

/**
 * 赛事项目Service业务层处理
 * 
 * @author ZJH
 * @date 2023-03-08
 */
@Service
public class EventServiceImpl implements IEventService 
{
    @Autowired
    private EventMapper eventMapper;

    @Autowired
    private SportsMeetingMapper sportsMeetingMapper;

    /**
     * 查询赛事项目
     * 
     * @param eventId 赛事项目主键
     * @return 赛事项目
     */
    @Override
    public EventVO selectEventByEventId(Long eventId)
    {
        Event event = eventMapper.selectEventByEventId(eventId);
        EventVO eventVO=new EventVO();
        BeanUtils.copyProperties(event,eventVO);
        SportsMeeting sportsMeeting = sportsMeetingMapper.selectSportsMeetingBySportsMeetingId(event.getSportsMeetingId());
        eventVO.setSportsMeetingName(sportsMeeting.getSportsMeetingName());
        eventVO.setApplicaitonStart(sportsMeeting.getApplicaitonStart());
        eventVO.setApplicaitonEnd(sportsMeeting.getApplicaitonEnd());
        return eventVO;
    }

    /**
     * 查询赛事项目列表
     * 
     * @param event 赛事项目
     * @return 赛事项目
     */
    @Override
    public List<EventVO> selectEventList(Event event)
    {
        List<Event> events = eventMapper.selectEventList(event);
        List<EventVO> eventVOList =new ArrayList<>();
        for (Event e:events){
            EventVO eventVO=new EventVO();
            BeanUtils.copyProperties(e,eventVO);
            SportsMeeting sportsMeeting = sportsMeetingMapper.selectSportsMeetingBySportsMeetingId(e.getSportsMeetingId());
            eventVO.setSportsMeetingName(sportsMeeting.getSportsMeetingName());
            eventVO.setApplicaitonStart(sportsMeeting.getApplicaitonStart());
            eventVO.setApplicaitonEnd(sportsMeeting.getApplicaitonEnd());
            eventVOList.add(eventVO);
        }
        return eventVOList;
    }

    /**
     * 新增赛事项目
     * 
     * @param event 赛事项目
     * @return 结果
     */
    @Override
    public int insertEvent(Event event)
    {
        return eventMapper.insertEvent(event);
    }

    /**
     * 修改赛事项目
     * 
     * @param event 赛事项目
     * @return 结果
     */
    @Override
    public int updateEvent(Event event)
    {
        return eventMapper.updateEvent(event);
    }

    /**
     * 批量删除赛事项目
     * 
     * @param eventIds 需要删除的赛事项目主键
     * @return 结果
     */
    @Override
    public int deleteEventByEventIds(Long[] eventIds)
    {
        return eventMapper.deleteEventByEventIds(eventIds);
    }

    /**
     * 删除赛事项目信息
     * 
     * @param eventId 赛事项目主键
     * @return 结果
     */
    @Override
    public int deleteEventByEventId(Long eventId)
    {
        return eventMapper.deleteEventByEventId(eventId);
    }
}
